package org.squabble.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.squabble.domain.SystemProperty;

@Repository
public class SystemPropertyDAOImpl extends AbstractHibernateDAO<SystemProperty>
		implements SystemPropertyDAO {

	@Autowired
	public SystemPropertyDAOImpl(SessionFactory sessionFactory) {
		super(SystemProperty.class, sessionFactory);
	}

	@Override
	public Map<String, SystemProperty> getSystemPropertyMap() {
		List<SystemProperty> props = this.all();
		Map<String, SystemProperty> propMap = new HashMap<String, SystemProperty>();
		for (SystemProperty systemProperty : props) {
			propMap.put(systemProperty.getName(), systemProperty);
		}
		return propMap;
	}

	@Override
	public SystemProperty getSystemProperty(String name) {
		return get(name);
	}

	@Override
	public void updateSystemProperty(SystemProperty systemProperty) {
		currentSession().update(systemProperty);
	}

	@Override
	public List<SystemProperty> getSystemProperties() {
		return this.all();
	}

}
